package com.example.studentmanagement.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.studentmanagement.MainActivity;
import com.example.studentmanagement.R;

public class HomeFragment extends Fragment implements OnClickListener {
	
	public static HomeFragment makeInstance() {		
		HomeFragment fragment = new HomeFragment();
		return fragment;
}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		ViewGroup view = (ViewGroup) inflater.inflate(R.layout.home_fragment, container, false);
		((Button)view.findViewById(R.id.btn_scan)).setOnClickListener(this);
		((Button)view.findViewById(R.id.btn_statistics)).setOnClickListener(this);
		return view;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}
	@Override
	public void onClick(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.btn_scan:
			if (getActivity() instanceof MainActivity) {
				QRCodeReaderFragment fragment = QRCodeReaderFragment.makeInstance();
				((MainActivity)getActivity()).switchContent(fragment);
			}
			break;
		case R.id.btn_statistics:
			if (getActivity() instanceof MainActivity) {
				
			}
			break;
		default:
			break;
		}
	}
	
}
